<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">

<py:def function="page_title">Game <span py:replace="game.game_id">#</span> - <span py:replace="game.display_name">[name]</span></py:def>
<py:def function="head_info">
    <script type="text/javascript">
        function update_server_clock()
        {
            var tzSign = ${tg.jsencode(tz_sign)};
            var tzHours = ${tg.jsencode(tz_hours)};
            var tzMinutes = ${tg.jsencode(tz_minutes)};
            
            var timeElem = $('current_server_time');
            var currentTime = isoTimestamp(scrapeText(timeElem));
            var currentTimeString = null;
            // Increment seconds
            currentTime.setUTCSeconds(currentTime.getUTCSeconds() + 1);
            // Format string
            currentTimeString = toISODate(currentTime) + "T" + toISOTime(currentTime, true) + tzSign + ((tzHours &lt; 10) ? "0" + tzHours : tzHours) + ":" + ((tzMinutes &lt; 10) ? "0" + tzMinutes : tzMinutes);
            // Change the element
            replaceChildNodes(timeElem, currentTimeString);
            // Thank you, call again! :)
            callLater(1, update_server_clock);
        }
    </script>
</py:def>
<py:def function="page_parents">
    <a href="${tg.url('/game/index')}">Games</a>
</py:def>

<py:match path="content">
    <a id="sect_game_info"></a>
    <table id="game_info" class="info_table">
        <tbody>
            <tr>
                <th>Current time:</th>
                <td><span id="current_server_time" class="date" py:content="tg.display_date(current_time)">[time]</span></td>
            </tr>
            <tr>
                <th>Created:</th>
                <td><span class="date" py:content="tg.display_date(game.created)">[date]</span></td>
            </tr>
            <tr>
                <th>Started:</th>
                <td><span py:choose="" py:strip=""><span py:when="game.started is None" py:strip="">Not yet started</span><span py:otherwise="" class="date" py:content="tg.display_date(game.started)">[date]</span></span></td>
            </tr>
            <tr>
                <th>Ended:</th>
                <td><span py:choose="" py:strip=""><span py:when="game.started is None" py:strip="">Not yet started</span><span py:when="game.ended is None" py:strip="">In progress</span><span py:otherwise="" class="date" py:content="tg.display_date(game.ended)">[date]</span></span></td>
            </tr>
            <tr>
                <th>Starve Time:</th>
                <td>
                    <span py:replace="tg.display_date(game.zombie_starve_timedelta)">[# hour(s)]</span>
                </td>
            </tr>
            <tr>
                <th>Report Time:</th>
                <td>
                    <span py:replace="tg.display_date(game.zombie_report_timedelta)">[# hour(s)]</span>
                </td>
            </tr>
            <tr py:if="game.ignore_weekdays">
                <th>Ignores weekdays:</th>
                <td>
                    <ul>
                        <li py:for="day in sorted(game.ignore_weekdays)"
                            py:content="tg.display_weekday(day)">[day]</li>
                    </ul>
                </td>
            </tr>
            <tr py:if="game.ignore_dates">
                <th>Holidays:</th>
                <td>
                    <ul>
                        <li py:for="date in sorted(game.ignore_dates)"
                            py:content="tg.display_date(date)">[date]</li>
                    </ul>
                </td>
            </tr>
        </tbody>
    </table>
    <div py:if="'edit-game' in tg.identity.permissions or 'delete-game' in tg.identity.permissions">
        <button py:if="'edit-game' in tg.identity.permissions" id="edit_button">Edit</button>
        <button py:if="'delete-game' in tg.identity.permissions" id="delete_button">Delete</button>
    </div>
    <p><a href="${tg.hvz.game_link(game, 'rules')}">Rules</a></p>
    <py:if test="current_entry is not None">
        <h2 id="sect_player_info">Your Info</h2>
        <ul>
            <li>Your ID is <span py:replace="current_entry.player_gid">[gid]</span></li>
            <li>You are <span py:replace="current_entry.affiliation">[affiliation]</span></li>
            <li py:if="current_entry.killed_by is not None">You were killed by <a href="${tg.hvz.user_link(current_entry.killed_by)}" class="player" py:content="current_entry.killed_by">[user]</a></li>
            <li py:if="not current_entry.is_human">
                You have killed
                <span py:replace="current_entry.kills">[#]</span>
                <span py:replace="tg.pluralize(current_entry.kills, _('player'), _('players'))">[player(s)]</span>
            </li>
            <li py:if="current_entry.starve_date is not None">You starved on <span py:replace="tg.display_date(current_entry.starve_date)">[date]</span></li>
            <li py:if="game.in_progress and current_entry.is_undead">You have <span py:replace="tg.display_date(current_entry.calculate_time_before_starving())">[time]</span> left before starving</li>
        </ul>
        <div py:if="game.in_progress and current_entry.can_report_kill()">
            <button id="report_kill_button">Report Kill</button>
        </div>
    </py:if>
    <h2 id="sect_entry_list">Player Roster</h2>
    <span py:replace="tg.display(grid, entries)">[players]</span>
    <div py:if="not tg.identity.anonymous">
        <button py:if="game.registration_open and current_entry is not None" id="unjoin_button">Unjoin</button>
        <button py:if="'join-game' in tg.identity.permissions and game.registration_open and current_entry is None" id="join_button">Join</button>
    </div>
    <h2 id="sect_stage">Stage</h2>
    <table id="stage_table">
        <tr py:for="value, name in sorted(game.STATE_NAMES.iteritems(), key=(lambda item: item[0]))">
            <td><img py:if="game.state >= value" class="check" src="${tg.url('/static/images/check.png')}" alt="Check" /></td>
            <td py:content="name">[state name]</td>
        </tr>
    </table>
    <form py:if="'stage-game' in tg.identity.permissions" action="${tg.url('/game/action.stage')}">
        <p>
            <input type="hidden" name="game_id" value="${game.game_id}" />
            <input py:if="not game.is_first_state" type="submit" name="btnPrev" value="Previous Stage" />
            <input py:if="not game.is_last_state" type="submit" name="btnNext" value="Next Stage" />
        </p>
    </form>
    <script type="text/javascript">
        // EVENTS //
        safe_connect('edit_button', 'onclick',
            function()
            {
                redirect(${tg.jsencode(tg.hvz.game_link(game, 'edit'))});
            });
        safe_connect('delete_button', 'onclick',
            function()
            {
                var delete_url = ${tg.jsencode(tg.hvz.game_link(game, 'action.delete'))};
                var msg = ${tg.jsencode(_("Are you sure you want to delete the game?"))};
                confirm_action(msg, delete_url);
            });
        safe_connect('report_kill_button', 'onclick',
            function()
            {
                redirect(${tg.jsencode(tg.hvz.game_link(game, 'reportkill'))});
            });
        safe_connect('unjoin_button', 'onclick',
            function()
            {
                var unjoin_url = ${tg.jsencode(tg.hvz.game_link(game, 'action.unjoin'))};
                var msg = ${tg.jsencode(_("Are you sure you want to remove yourself from the game?"))};
                confirm_action(msg, unjoin_url);
            });
        safe_connect('join_button', 'onclick',
            function()
            {
                redirect(${tg.jsencode(tg.hvz.game_link(game, 'join'))});
            });
        // CLOCK //
        callLater(1, update_server_clock);
    </script>
</py:match>

<xi:include href="../master.html" />

</html>
